{extend name="base" /}
{block name="content"}
<div class="layui-fluid">
  <div class="layui-card">
    <form class="layui-form" action="{:url('admin/dp/edit_review')}" method="post">
      <input type="hidden" name="id" value="{$review.id}">

      <div class="layui-form-item">
        <label class="layui-form-label">课程名称</label>
        <div class="layui-input-block">
          <input type="text" name="course_name" value="{$review.course_name}" required lay-verify="required" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">师资团队</label>
        <div class="layui-input-block">
          <input type="text" name="expert_team" value="{$review.expert_team}" class="layui-input">
        </div>
      </div>
       <div class="layui-form-item">
  <label class="layui-form-label">师资</label>
  <div class="layui-input-block">
        {foreach name="expert_list" item="expert"}
<input type="checkbox" name="expert_ids[]" title="{$expert.name}" value="{$expert.id}" 
    {if in_array($expert.id, $review.expert_ids)}checked{/if}>
    {/foreach}
  </div>
</div>
      <div class="layui-form-item">
        <label class="layui-form-label">标题图片</label>
        <div class="layui-input-inline">
          <input type="text" name="cover_img" id="cover_img" value="{$review.cover_img}" class="layui-input">
        </div>
        <button type="button" class="layui-btn" id="upload_img">上传图片</button>
      </div>
      {if $review.cover_img}
      <div class="layui-form-item">
        <div class="layui-input-block">
          <img id="preview_img" src="{$review.cover_img}" style="max-width:200px;">
        </div>
      </div>
      {/if}

      <div class="layui-form-item">
        <label class="layui-form-label">回顾视频</label>
        <div class="layui-input-inline">
          <input type="text" name="video_url" id="video_url" value="{$review.video_url}" class="layui-input">
        </div>
        <button type="button" class="layui-btn" id="upload_video">上传视频</button>
      </div>
      {if $review.video_url}
      <div class="layui-form-item">
        <div class="layui-input-block">
          <video id="preview_video" src="{$review.video_url}" controls style="max-width:300px; max-height:150px;"></video>
        </div>
      </div>
      {/if}

      <div class="layui-form-item">
        <label class="layui-form-label">介绍</label>
        <div class="layui-input-block">
          <textarea name="description" class="layui-textarea">{$review.description}</textarea>
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="submitReviewEdit">提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
{/block}

{block name="js"}
<script>
layui.use(['form', 'upload'], function(){
  var form = layui.form,
      upload = layui.upload;

  upload.render({
    elem: '#upload_img',
    url: '/index/index/upload',
    field: 'file',
    done: function(res){
      if(res.code === 1){
        var url = '/public/' + res.data.url;
        $('#cover_img').val(url);
        $('#preview_img').attr('src', url).show();
        layer.msg('上传成功');
      } else {
        layer.msg('上传失败');
      }
    }
  });

  upload.render({
    elem: '#upload_video',
    url: '/index/index/upload',
    accept: 'video',
    field: 'file',
    done: function(res){
      if(res.code === 1){
        var url = '/public/' + res.data.url;
        $('#video_url').val(url);
        $('#preview_video').attr('src', url).show();
        layer.msg('上传成功');
      } else {
        layer.msg('上传失败');
      }
    }
  });

  form.on('submit(submitReviewEdit)', function(data){
    $.ajax({
      url: data.form.action,
      type: data.form.method,
      data: $(data.form).serialize(),
      success: function(info){
        if(info.code === 1){
          setTimeout(function(){
            window.location.href = "{:url('admin/dp/review')}";
          }, 1000);
        }
        layer.msg(info.msg);
      }
    });
    return false;
  });
});
</script>
{/block}
